# -*- coding: utf-8 -*-

from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator
from datetime import timedelta
# from jms.ods.oms.yl_oms_oms_waybill import jms_ods__yl_oms_oms_waybill
from jms.dwd.oms.dwd_yl_oms_oms_waybill_incre_dt import jms_dwd__dwd_yl_oms_oms_waybill_incre_dt
from jms.dwd.oms.dwd_oms_waybill_extend_base_dt import jms_dwd__dwd_oms_waybill_extend_base_dt

jms_dm__dm_nosign_waybill_dt = SparkSqlOperator(
    task_id='jms_dm__dm_nosign_waybill_dt',
    task_concurrency=1,
    pool_slots=3,
    master='yarn',
    name='jms_dm__dm_nosign_waybill_dt_{{ execution_date | date_add(1) | cst_ds }}',
    sql='jms/dm/dm_nosign_waybill_dt/execute.hql',
    execution_timeout=timedelta(minutes=55),
    email=['lukunming@jtexpress.com','yl_bigdata@yl-scm.com'],
    driver_cores=4,
    driver_memory='8G',
    executor_cores=2,
    executor_memory='4G',
    num_executors=8,  # spark.dynamicAllocation.enabled 为 True 时，num_executors 表示最少 Executor 数
    conf={'spark.dynamicAllocation.enabled'                  : 'true',  # 动态资源开启
          'spark.shuffle.service.enabled'                    : 'true',  # 动态资源 Shuffle 服务开启
          #'spark.dynamicAllocation.maxExecutors'             : 36,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.maxExecutors'             : 22,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 120,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode'         : 'dynamic',  # 允许删改已存在的分区
          'spark.executor.memoryOverhead'                    : '2G',  # 堆外内存
          'spark.sql.shuffle.partitions'                     : 1200,
          'spark.default.paralleism'                         : 1200,
          }
)

jms_dm__dm_nosign_waybill_dt << [
    jms_dwd__dwd_oms_waybill_extend_base_dt,
    jms_dwd__dwd_yl_oms_oms_waybill_incre_dt,
]
